 package com.gmrz.uaf.server.validation;
 
 import com.gmrz.uaf.protocol.v1.processor.exception.RegistrationFailedException;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
 public class MaxRegValidator
 {
   private static final Logger LOG = LogManager.getLogger(MaxRegValidator.class);
 
   public void validateAuthenticatorsCount(int regAuthenticatorCount, int toBeRegisteredAuthenticatorsCount, int regAuthenticatorsLimit, String username)
   {
     LOG.debug("authenticator count from database is [{}], count of authenticators to be registered is [{}] and authenticator limit [{}]", Integer.valueOf(regAuthenticatorCount), Integer.valueOf(toBeRegisteredAuthenticatorsCount), Integer.valueOf(regAuthenticatorsLimit));
 
     int totalAuthenticatorsCount = regAuthenticatorCount + toBeRegisteredAuthenticatorsCount;
 
     String errorMsg = null;
 
     if (regAuthenticatorCount >= regAuthenticatorsLimit) {
       LOG.error("Registration for additional [{}] authenticators can not be completed for user [{}], given registered authenticators count [{}] and the allowed limit of [{}]", Integer.valueOf(toBeRegisteredAuthenticatorsCount), username, Integer.valueOf(regAuthenticatorCount), Integer.valueOf(regAuthenticatorsLimit));
 
       if (regAuthenticatorCount == regAuthenticatorsLimit) {
         errorMsg = "Maximum limit for number of authenticators for this user reached.";
         throw new RegistrationFailedException(errorMsg);
       }
 
       LOG.error("Registered authenticators count [{}] for user [{}] is already exceeding the allowed authenticators limit [{}]", Integer.valueOf(regAuthenticatorCount), username, Integer.valueOf(regAuthenticatorsLimit));
 
       errorMsg = "Registered authenticators count for this user is already exceeding the allowed authenticators limit.";
       throw new RegistrationFailedException(errorMsg);
     }
 
     if (totalAuthenticatorsCount > regAuthenticatorsLimit) {
       LOG.error("Maximum limit for number of authenticators [{}] for user [{}] will exceed on completing registration.", Integer.valueOf(regAuthenticatorsLimit), username);
 
       errorMsg = "Maximum limit for number of authenticators for this user will exceed on completing registration.";
       throw new RegistrationFailedException(errorMsg);
     }
   }
 }
